/**
 * 
 */
package com.lehecai.core.api.user;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.lehecai.core.api.AbstractApiResultBean;
import com.lehecai.core.lottery.SourceStatus;

/**
 * @author Sunshow
 * 渠道来源
 */
public class Source extends AbstractApiResultBean {
	
	public static final String QUERY_ID = "id";
	public static final String QUERY_PARTNER_ID = "partner_id";
	public static final String QUERY_NAME = "name";
	public static final String QUERY_STATUS = "status";
	public static final String QUERY_SOURCE = "source";
	
	public static final String SET_ID = "id";
	public static final String SET_PARTNER_ID = "partner_id";
	public static final String SET_NAME = "name";
	public static final String SET_STATUS = "status";
	public static final String SET_SOURCE = "source";
	
	private Long id;					//ID
	private String name;			//渠道名称
	private Long partnerId; 		//渠道合作商ID
	private SourceStatus status;	//来源状态
    private String partnerName;    //渠道来源名称

	public static String getSourceDisplayName(long sourceId) {
		if (sourceId == 5732) {
			return "百度游戏";
		}
		if (sourceId == 5734) {
			return "百度贴吧彩票";
		}
		if (sourceId / 1000 == 5) {
			return "百度乐彩";
		}
		if (sourceId / 1000 == 9) {
			return "虎扑彩票";
		}
		if (sourceId == 4018) {
			return "彩宝贝";
		}
		if (sourceId == 4012) {
			return "中华网彩票";
		}
		if (sourceId == 4050) {
			return "东南网彩票";
		}
		if (sourceId == 5500) {
			return "hao123彩票";
		}
		if (sourceId == 4079 || sourceId == 4081 || sourceId == 4082 || sourceId == 4083 || sourceId == 4084) {
			return "520彩票";
		}
		if (sourceId == 4090) {
			return "智彩彩票";
		}
		if (sourceId == 4075) {
			return "中国资本证券网彩票频道";
		}
		if (sourceId == 4097) {
			return "acfun彩票";
		}
		if (sourceId == 4121) {
			return "老K游戏彩票";
		}
		
		if (sourceId == 4040 || sourceId == 4041) {
			return "518彩";
		}

        if (sourceId == 6158) {
            return "58彩票";
        }

        if (sourceId == 1000) {
            return "百度彩票";
        }

		if (sourceId >= 6789 && sourceId <= 6791) {
			return "搜狐彩票";
		}
		if (sourceId >= 4028 && sourceId <= 4035) {
			return "暴风彩票";
		}
		return "百度乐彩";
	}
	
	public static Source convertFromJSONObject(JSONObject object) {
		if (object == null) {
			return null;
		}
		Source source = new Source();
		source.id = getLong(object, "id");
		source.name = getString(object, "name");
		source.partnerId = getLong(object, "partner_id");
		int iStatus = getInt(object, "status");
		if (iStatus >= 0) {
			source.status = SourceStatus.getItem(iStatus);
		}
		if (object.containsKey("partner_name")) {
            source.partnerName = getString(object, "partner_name");
        }
		return source;
	}
	
	@SuppressWarnings("unchecked")
	public static List<Source> convertFromJSONArray(JSONArray array) {
		if (array == null) {
			return null;
		}
		List<Source> list = new ArrayList<Source>();
		for (Iterator iterator = array.iterator(); iterator.hasNext();) {
			JSONObject object = (JSONObject) iterator.next();
			list.add(convertFromJSONObject(object));
		}
		return list;
	}

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getPartnerId() {
        return partnerId;
    }

    public void setPartnerId(Long partnerId) {
        this.partnerId = partnerId;
    }

    public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public SourceStatus getStatus() {
		return status;
	}

	public void setStatus(SourceStatus status) {
		this.status = status;
	}

    public String getPartnerName() {
        return partnerName;
    }

    public void setPartnerName(String partnerName) {
        this.partnerName = partnerName;
    }
}
